package file;

import java.io.*;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ASUS
 * Date: 2025-02-28
 * Time: 11:09
 */
public class Demo11 {
    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        System.out.println("请输入要复制的文件路径: ");
        String src = s.next();
        File srcFile = new File(src);
        if (!srcFile.isFile()) {
            System.out.println("您输入的源文件路径非法!");
            return;
        }
        System.out.println("请输入要复制的目标路径: ");
        String dest = s.next();
        File destFile = new File(dest);
        if (!destFile.getParentFile().isDirectory()) {
            System.out.println("您输入的目标文件路径非法! ");
            return;
        }
        try (InputStream inputStream = new FileInputStream(srcFile);
             OutputStream outputStream = new FileOutputStream(destFile)){
            while (true) {
                byte[] buffer = new byte[20480];
                int n = inputStream.read(buffer);
                System.out.printf("n = %x", n);
                if (n == -1) {
                    System.out.println("读取到 eof, 循环结束");
                    break;

                }
                outputStream.write(buffer,0,n);
            }
        }
    }
}
